package com.fastloan.mgt.product.flow.controller;

import com.fastloan.mgt.log.aspect.SystemLog;
import com.fastloan.mgt.product.expection.ProductApproveException;
import com.fastloan.mgt.product.flow.model.ProductFlow;
import com.fastloan.mgt.product.flow.service.ProductFlowService;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultEnum;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chenkai
 *         createTime 2017-11-2017/11/8 15:45
 */
@RestController
@RequestMapping("/api/web/productFlow")
public class ProductFlowController extends BaseController<ProductFlow> {
    @Autowired
    private ProductFlowService productFlowService;

    /**
     * 获取产品流程
     * @param productId
     * @return
     */
    @GetMapping("/{productId}")
    public ResultTo ProcessFunction(@PathVariable String productId) {
        return new ResultTo().setData(productFlowService.getProcessFunction(productId));
    }

    /**
     * 配置产品流程
     * @param productFlowList
     * @return
     */
    @PostMapping
    @SystemLog(description="配置产品流程")
    public ResultTo pageFlow(@RequestBody List<ProductFlow> productFlowList) {
        try {
            return productFlowService.pageFlow(productFlowList) != null
                    ? new ResultTo() : new ResultTo(ResultEnum.OPERATION_FAILED);
        } catch (ProductApproveException e) {
            e.printStackTrace();
            return new ResultTo(ResultEnum.OPERATION_FAILED, e.getMessage());
        }
    }

}
